//
//  SRcsemActivity.m
//  sr01sdkProject
//
//  Created by Linktop on 2024/8/30.
//

#import "CAnAlgGrandActivity2.h"

@implementation CAnAlgGrandActivity2
-(NSNumber *)dataTimeStamp
{
    return @(self.timeStamp);
}

- (instancetype)initWithData:(NSData *)data
{
    self = [super init];
    if (self) {
        
        if (data.length < 20) {
            return self;
        }
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        
        self->_cmdByte = dataBytes[1];
        
        // 2, 3, 4 年月日
        uint8_t year = dataBytes[2];
        uint8_t month = dataBytes[3];
        uint8_t day = dataBytes[4];
        
        _year = year;
        _month = month;
        _day = day;
        
        NSDateFormatter *fmt = [NSDateFormatter new];
        fmt.dateFormat = @"yyyy-MM-dd";
        NSDate *date = [fmt dateFromString:[NSString stringWithFormat:@"%d-%02d-%02d",year+2000, month, day]];

        _timeStamp = (NSUInteger)(date.timeIntervalSince1970);
        
        // 5, 6  总的走路步数
        _totalWalkSteps = *((uint16_t *)(dataBytes + 5));
        
        // 7, 8 总的跑步步数
        _totalRunSteps = *((uint16_t *)(dataBytes + 7));
        
        // 9, 10 总的其它步数
        _totalOtherSteps = *((uint16_t *)(dataBytes + 9));
        
        // 11, 12 总距离
        _totalDistance = *((uint16_t *)(dataBytes + 11));
         
        // 13, 14 总的走路距离
        _totalWalkDistance = *((uint16_t *)(dataBytes + 13));
        // 15, 16 跑步距离
        _totalRunDistance = *((uint16_t *)(dataBytes + 15));
        // 17, 18 其他距离
        _totalOtherDistance = *((uint16_t *)(dataBytes + 17));
        

    }
    return self;
}

@end
